"use strict";

var SHARE = {
    marquerrMove: function marquerrMove() {
        var a = $("#msgBox");
        var b = function b() {
            var b = -1 * parseInt(a.find("li").eq(0).height());
            a.find("ul").animate({
                "margin-top": b + "px"
            }, function () {
                a.find("ul li:eq(0)").appendTo(a.find("ul")), a.find("ul").css({
                    "margin-top": 0
                });
            });
        };
        setInterval(b, 3000);
    },
    popup: function popup(ex) {
        ex ? $('.mask').show().next().show() : $('.mask').hide().next().hide();
    },
    //获取页面url参数；
    GetQueryString: function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return r[2];return null;
    },
    isWeiXin: function isWeiXin() {
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true;
        } else {
            return false;
        }
    },
    downLoad: function downLoad() {
        window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.ppdai.huanapp";
    }
};
//获取渠道参数；
var mobile;
var isWx = SHARE.isWeiXin(),
    isiOS = navigator.userAgent.match('iPad') || navigator.userAgent.match('iPhone') || navigator.userAgent.match('iPod'),
    dlurl = SHARE.GetQueryString("url"),
    iosURL = !dlurl ? "https://itunes.apple.com/cn/app/jie-zou-da-shi/id1176078944?mt=8" : dlurl,
    isAndroid = navigator.userAgent.match('Android');
var uId = SHARE.GetQueryString("shareId");
uId = !uId ? 0 : uId;
var _src = SHARE.GetQueryString("source");
_src = !_src ? "" : _src;
//点击传值并下载；
$('#getBtn').on('click', function () {
    mobile = $.trim($('#phoneNum').val());
    if (mobile.length < 1) {
        $('#phoneNum').attr('placeholder', '请先输入手机号~').addClass('redPlhd');
        return;
    } else if (!/^(13|14|15|17|18)[0-9]{9}$/.test(mobile)) {
        $('#phoneNum').val('').attr('placeholder', '请输入正确的手机号~').addClass('redPlhd');
        return;
    }
    $.ajax({
        type: 'get',
        async: false,
        dataType: 'json',
        url: "//m.ppdai.com/Activity/InviteNewUser",
        data: { mobile: mobile, shareId: uId, source: 1 },
        success: function success(data) {
            if (data.Result == 0) {
                if (data.Content.IsNewUser) {
                    window.location.href = "register.html?phoneNum=" + mobile + "&shareId=" + uId + "&source=" + _src;
                } else {
                    SHARE.popup(true);
                }
            } else {
                alert(data.ResultMessage);
            }
        },
        error: function error(XMLHttpRequest, textStatus, errorThrown) {
            alert("网络错误,请稍后重试~");
        }
    });
});
$('#dwload').on('click', function () {
    SHARE.popup(false);
    SHARE.downLoad();
});